package script.esxi;

import cn.com.betasoft.dsat.probe.groovy.SimException;
/**
 原生变量：g_col_pars g_col_other g_rets
 原生变量：g_res(g_shc, g_dbcon)
 返回的数据：返回数组[]
~ # esxcfg-nics -l
Name    PCI           Driver      Link Speed     Duplex MAC Address       MTU    Description
vmnic0  0000:06:00.00 e1000e      Down 0Mbps     Half   00:25:90:01:ab:a6 1500   Intel Corporation 82574L Gigabit Network Connection
vmnic1  0000:07:00.00 e1000e      Up   1000Mbps  Full   00:25:90:01:ab:a7 1500   Intel Corporation 82574L Gigabit Network Connection

 */

def json = [];
//获取数据
def String ret = g_shc.collect('''esxcfg-nics -l''');
if(ret.contains("command not found")){
	throw new SimException(8013,"ESXi.NetworkCardInfo:没有找到命令.");
}
if(ret.contains("Permission denied")){
	throw new SimException(8014,"ESXi.NetworkCardInfo:没有权限执行命令.");
}
def matched = false;
ret.split("\n").each{
	matched = true;
	def matcher = (it =~ /(\S+\d+)\s+(\d+\:\d+\:\d+\.\d+)\s+(\S+\d+\S+)\s+(\S+)\s+(\d+\S+)\s+(\S+)\s+(.*)\s+(\d+)\s+(.*)/);
	if (matcher.matches()){
		def netCard =['Name':'','Status':'','Type':''];
		netCard['Name'] = matcher[0][1];
		netCard['Type'] = matcher[0][3];
		netCard['Status'] = matcher[0][4];
		json.add(netCard);
	}
};
if(!matched){
	throw new SimException(8015,"ESXi.NetworkCardInfo:返回数据不匹配.");
}
//序列化返回
g_rets = json;